package com.itboye.jmsfhz.app.ui.me;

import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.itboye.core.object.BaseActivity;
import com.itboye.jmsfhz.R;

public class BaseWebViewActivity extends BaseActivity{
	private LinearLayout openMenu;
	private WebView webview;
	private ProgressDialog pd;
	private TextView txt_title;
	String title;
	private String url="http://baidu.com";
	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_web;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		title = getIntent().getStringExtra("title");
		url = getIntent().getStringExtra("url");
		txt_title.setText(title);
		webview.loadUrl(url);
		webview.requestFocus();
		webview.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView view, int progress) {
				pd.setMessage("正在加载" + progress + "%");
//				showProgressDialog("正在加载中"+progress, true);
			}
		});
		webview.setWebViewClient(new MyWebViewClient());
		
	}
	public class MyWebViewClient extends WebViewClient {

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			// 设置点击网页里面的链接还是在当前的webview里跳转
			view.loadUrl(url);
			return true;
		}

		// 设置页面加载前的事件
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			// TODO Auto-generated method stub
			super.onPageStarted(view, url, favicon);
			pd.show();
		}

		// 设置页面加载后的事件
		@Override
		public void onPageFinished(WebView view, String url) {
			// TODO Auto-generated method stub
			super.onPageFinished(view, url);
			// pd.cancel();
			pd.dismiss();
		}

		public void onReceivedError(WebView view, int errorCode,
				String description, String failingUrl) {
			// 加载页面报错时的处理
			Toast.makeText(BaseWebViewActivity.this, "Oh no! " + description,
					Toast.LENGTH_SHORT).show();
		}

	}

}
